package com.wkbb.sports.controller;

import com.github.pagehelper.PageInfo;
import com.wkbb.common.base.BaseController;
import com.wkbb.common.constants.VersionConstant;
import com.wkbb.common.dto.ResultDTO;
import com.wkbb.sports.model.HlifeWorkStudent;
import com.wkbb.sports.service.PcWorkService;
import com.wkbb.sports.service.WorkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * @author lbh
 * @date 2021年03月29日 17:58:34
 * @description:   PC端作业控制类
 */
@RestController
@Api(tags = "PC端作业接口")
@RequestMapping("/sports/{apiVersion}/pcWork")
@Slf4j
public class PcWorkController extends BaseController {

    @Autowired
    private WorkService workService;

    @Autowired
    private PcWorkService pcWorkService;

    @ApiOperation(value = "跳绳作业个人统计【PC端】")
    @RequestMapping(value = "getStudentPersonalInfoDetailForPcIndex", method = RequestMethod.GET)
    public ResultDTO<Map<String,Object>> getStudentPersonalInfoDetailForPc(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "学生ID", required = true) @RequestParam(name = "studentId", required = true) Long studentId,
            @ApiParam(value = "分页数", defaultValue = "0", required = false) @RequestParam(name = "pageNo", defaultValue = "0", required = false) int pageNo,
            @ApiParam(value = "分页大小", defaultValue = "20", required = false) @RequestParam(name = "pageSize", defaultValue = "20", required = false) int pageSize){
        return workService.getStudentPersonalInfoDetailForPc(studentId,pageNo,pageSize);
    }

    @ApiOperation(value = "获取PC端默认首页数据【1、统计】")
    @RequestMapping(value = "getPcIndex", method = RequestMethod.GET)
    public ResultDTO getPcIndex(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "学校ID", required = true) @RequestParam(name = "orgId", required = true) String orgId,
            @ApiParam(value = "教师ID", required = true) @RequestParam(name = "teacherId", required = true) String teacherId,
            @ApiParam(value = "班级ID", required = false) @RequestParam(name = "classId", required = false) String classId){
        return pcWorkService.getPcIndex(teacherId,orgId,classId);
    }

    @ApiOperation(value = "获取PC端默认首页数据【2、本年级平均成绩结构对比】")
    @RequestMapping(value = "getPcIndex2", method = RequestMethod.GET)
    public ResultDTO getPcIndex2(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "学校ID", required = true) @RequestParam(name = "orgId", required = true) String orgId,
            @ApiParam(value = "年级名称(一年级, 二年级, 三年级, 四年级, 五年级, 六年级, 初一, 初二, 初三, 高一, 高二, 高三)", required = true) @RequestParam(name = "gradeName", required = true) String gradeName,
            @ApiParam(value = "年月份时间(示例值：2021-05【默认当前系统月份】)", required = false) @RequestParam(name = "time", required = false) String time){
        return pcWorkService.getPcIndex2(gradeName,orgId,time);
    }

    @ApiOperation(value = "获取PC端默认首页数据【3、我的作业布置统计】")
    @RequestMapping(value = "getPcIndex3", method = RequestMethod.GET)
    public ResultDTO getPcIndex3(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "学校ID", required = true) @RequestParam(name = "orgId", required = true) String orgId,
            @ApiParam(value = "教师ID", required = true) @RequestParam(name = "teacherId", required = true) String teacherId,
            @ApiParam(value = "班级id", required = false) @RequestParam(name = "classId", required = false) Integer classId,
            @ApiParam(value = "年月份时间(示例值：2021-05【默认当前系统月份】)", required = false) @RequestParam(name = "time", required = false) String time){
        return pcWorkService.getPcIndex3(teacherId,orgId,time,classId);
    }

    @ApiOperation(value = "获取PC端默认首页数据【4、学生作业提交率】")
    @RequestMapping(value = "getPcIndex4", method = RequestMethod.GET)
    public ResultDTO getPcIndex4(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "学校ID", required = true) @RequestParam(name = "orgId", required = true) String orgId,
            @ApiParam(value = "教师ID", required = true) @RequestParam(name = "teacherId", required = true) String teacherId,
            @ApiParam(value = "班级id", required = false) @RequestParam(name = "classId", required = false) Integer classId,
            @ApiParam(value = "年月份时间(示例值：2021-05【默认当前系统月份】)", required = false) @RequestParam(name = "time", required = false) String time){
        return pcWorkService.getPcIndex4(teacherId,orgId,time,classId);
    }

    @ApiOperation(value = "作业下拉选择列表")
    @RequestMapping(value = "getWorksByTeacherIdForPc", method = RequestMethod.GET)
    public ResultDTO<List<Map<String,Object>>> getWorksByTeacherIdForPc(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "学校ID", required = true) @RequestParam(name = "orgId", required = true) Integer orgId,
            @ApiParam(value = "教师ID", required = true) @RequestParam(name = "teacherId", required = true) Integer teacherId,
            @ApiParam(value = "班级id", required = false) @RequestParam(name = "classId", required = false) Integer classId,
            @ApiParam(value = "年月份时间(示例值：2021-05【默认当前系统月份】)", required = false) @RequestParam(name = "time", required = false) String time
            ){
        return pcWorkService.getWorksByTeacherIdForPc(teacherId, orgId,classId,time);
    }

    @ApiOperation(value = "首页作业列表")
    @RequestMapping(value = "getIndexWorksByTeacherIdForPc", method = RequestMethod.GET)
    public ResultDTO<PageInfo<HlifeWorkStudent>> getIndexWorksByTeacherIdForPc(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "作业ID", required = true) @RequestParam(name = "workId", required = true) Integer workId,
            @ApiParam(value = "年月份时间(示例值：2021-05【默认当前系统月份】)", required = false) @RequestParam(name = "time", required = false) String time,
            @ApiParam(value = "分页数", defaultValue = "1", required = false) @RequestParam(name = "pageNo", defaultValue = "1", required = false) int pageNo,
            @ApiParam(value = "分页大小", defaultValue = "20", required = false) @RequestParam(name = "pageSize", defaultValue = "20", required = false) int pageSize
    ){
        return pcWorkService.getIndexWorksByTeacherIdForPc(workId,time, pageNo, pageSize);
    }

    @ApiOperation(value = "作业列表")
    @RequestMapping(value = "getWorkListByTeacherIdForPc", method = RequestMethod.GET)
    public ResultDTO getWorkListByTeacherIdForPc(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "学校ID", required = true) @RequestParam(name = "orgId", required = true) Integer orgId,
            @ApiParam(value = "教师ID", required = true) @RequestParam(name = "teacherId", required = true) Integer teacherId,
            @ApiParam(value = "作业状态(0未开始 1进行中2已结束3已取消)", required = false) @RequestParam(name = "status", required = false) Integer status,
            @ApiParam(value = "作业类型(1模拟考试 2限时限数3数量模式4时间模式)", required = false) @RequestParam(name = "type", required = false) Integer type,
            @ApiParam(value = "班级id", required = false) @RequestParam(name = "classId", required = false) Integer classId,
            @ApiParam(value = "标志(0查询【默认】/1导出excel)", defaultValue = "0", required = false) @RequestParam(name = "flag", defaultValue = "0", required = false) String flag,
            //@ApiParam(value = "成绩范围(示例值为：80或者80-90)", required = false) @RequestParam(name = "achivement", required = false) String achivement,
            @ApiParam(value = "分页数", defaultValue = "1", required = false) @RequestParam(name = "pageNo", defaultValue = "1", required = false) int pageNo,
            @ApiParam(value = "分页大小", defaultValue = "20", required = false) @RequestParam(name = "pageSize", defaultValue = "20", required = false) int pageSize,
            HttpServletResponse response){
        return pcWorkService.getWorkListByTeacherIdForPc(teacherId, status,type, classId,orgId,pageNo,pageSize,flag,response);
    }

    @ApiOperation(value = "删除作业")
    @RequestMapping(value = "endAndStartWorkInfo", method = RequestMethod.POST)
    public ResultDTO endAndStartWorkInfo(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "作业ID", required = true) @RequestParam(name = "workId", required = true) String workId,
            @ApiParam(value = "作业状态(0未开始 1进行中2已结束3已取消)", required = true) @RequestParam(name = "status", required = true) String status){
        return workService.endAndStartWorkInfo(workId,status);
    }

    @ApiOperation(value = "作业详情及统计")
    @RequestMapping(value = "getWorkDetailForPc", method = RequestMethod.GET)
    public ResultDTO<Map<String,Object>> getWorkDetailForPc(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "作业ID", required = true) @RequestParam(name = "workId", required = true) Long workId){
        return pcWorkService.getWorkDetailForPc(workId);
    }

    @ApiOperation(value = "作业学生详情")
    @RequestMapping(value = "getWorkDetailStudentForPc", method = RequestMethod.GET)
    public ResultDTO getWorkDetailStudentForPc(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "作业ID", required = true) @RequestParam(name = "workId", required = true) String workId,
            @ApiParam(value = "学生学号", required = false) @RequestParam(name = "studentNo", defaultValue = "",required = false) String studentNo,
            @ApiParam(value = "学生姓名", required = false) @RequestParam(name = "studentName", defaultValue = "",required = false) String studentName,
            @ApiParam(value = "达标(0未达标,1已达标)", required = false) @RequestParam(name = "reached", defaultValue = "",required = false) String reached,
            @ApiParam(value = "作业状态(0未开始 1进行中2已结束3已取消)", required = false) @RequestParam(name = "status", required = false) Integer status,
            @ApiParam(value = "性别(1男/2女)", required = false) @RequestParam(name = "sex", required = false) Integer sex,
            @ApiParam(value = "标志(0查询【默认】/1导出excel)", defaultValue = "0", required = false) @RequestParam(name = "flag", defaultValue = "0", required = false) String flag,
            @ApiParam(value = "分页数", defaultValue = "1", required = false) @RequestParam(name = "pageNo", defaultValue = "1", required = false) int pageNo,
            @ApiParam(value = "分页大小", defaultValue = "20", required = false) @RequestParam(name = "pageSize", defaultValue = "20", required = false) int pageSize,
            HttpServletResponse response){
        return pcWorkService.getWorkDetailStudentForPc(workId,studentNo,studentName,reached,status,sex,pageNo,pageSize, flag,response);
    }

    @ApiOperation(value = "个人作业记录【时长模式】【PC端】")
    @RequestMapping(value = "getStudentPersonalInfoDetailForPc", method = RequestMethod.GET)
    public ResultDTO<Map<String,Object>> getStudentPersonalInfoDetailForPc(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "学校ID", required = true) @RequestParam(name = "orgId", required = true) String orgId,
            @ApiParam(value = "作业ID", required = false) @RequestParam(name = "workId", required = false) String workId,
            @ApiParam(value = "学生ID", required = true) @RequestParam(name = "studentId", required = true) String studentId,
            @ApiParam(value = "教师姓名", required = false) @RequestParam(name = "teacherName", required = false) String teacherName,
            @ApiParam(value = "成绩范围(示例值为：80或者80-90)", required = false) @RequestParam(name = "achivement", required = false) String achivement,
            @ApiParam(value = "主键ID", required = false) @RequestParam(name = "studentHistoryId", required = false) String studentHistoryId,
            @ApiParam(value = "标志(0查询【默认】/1导出excel)", defaultValue = "0", required = false) @RequestParam(name = "flag", defaultValue = "0", required = false) String flag,
            @ApiParam(value = "分页数", defaultValue = "1", required = false) @RequestParam(name = "pageNo", defaultValue = "1", required = false) int pageNo,
            @ApiParam(value = "分页大小", defaultValue = "20", required = false) @RequestParam(name = "pageSize", defaultValue = "20", required = false) int pageSize,
            HttpServletResponse response){
        return pcWorkService.getStudentPersonalInfoDetailForPc(workId,studentId,studentHistoryId,orgId,teacherName,achivement,pageNo,pageSize, flag,response);
    }

    /*@RequestMapping(value = "testExcel", method = RequestMethod.GET)
    public void testExcel(HttpServletResponse response)  throws IOException {
        pcWorkService.testExcel(response);
    }

    @RequestMapping(value = "testExcel1", method = RequestMethod.GET)
    public ResultDTO testExcel1(HttpServletResponse response)  throws IOException{
        return pcWorkService.testExcel1(response);
    }*/

}